<?php
/* {
Citru - www.citru.se
See license.txt for copyright and license information.
} */

if(!defined("_CITRU")) {die('This file should not be accessed directly.');}
require_once 'Module.php';

class AdminNavModule extends Module {
	
	protected $moduleTabs = array("view", "permissions");
	protected $moduleName = "AdminNavModule";
	protected $instanceName;
	protected $dbModule;
	protected $permissions;
	
	function __construct($instance, $db_module, $permissions) {
		$this->instanceName = $instance;
		$this->dbModule = $db_module;
		$this->permissions = $permissions;
	}
	
	/**
	 * Adds the necessary table for the module
	 *
	 * @return void
	 */
	public function installTables() {
		// Add global permissions
		$params_perm = array(	'table' => 'Permissions',
        						'set' => array(	'module'=>$this->moduleName,
								'permissions'=>"view=@admin\npermissions=@admin"));
        if(!$this->dbModule->insertRow($params_perm)) {
			throw new Exception('Could not create global permissions for '.$this->moduleName.'.');
		}
	}
	
	/**
	 * Returns a navigation bar for administration of Citru
	 *
	 * @return string		html for the navigation bar
	 */
	public function getView() {
		$nav .= '<a class="citru_button" href="'.ROOT.'"><img src="'.ROOT.'inc/icons/home.png" /> Home</a>';  	
		$nav .= '<a class="citru_button" href="'.ROOT.'admin/pages_panel.php"><img src="'.ROOT.'inc/icons/templates.png" /> Templates</a>';
	   	$nav .= '<a class="citru_button" href="'.ROOT.'admin/users_panel.php"><img src="'.ROOT.'inc/icons/users.png" /> Manage users</a>';
	   	$nav .= '<a class="citru_button" href="'.ROOT.'admin/?logout"><img src="'.ROOT.'inc/icons/logout.png" /> Log out</a>';
		$nav .= '</div>';
		return $nav;
	}
	
	/**
	 * Returns the selected tab of the admin view
	 *
	 * @param string $tab 	selected tab
	 * @return string		html for the selected tab
	 */
	protected function getAdminTab($tab="view") {
		switch($tab) {
			case "permissions":
				return $this->getPermissionsForm();
			default:
				return $this->getView();
		}
	}
		
}

?>
